package com.lwj.liwanjia.utils;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.lwj.liwanjia.MainActivity;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.adapter.KuaiDiAdapter;
import com.lwj.liwanjia.view.activity.myindent.MyIndentActivity;
import com.lwj.liwanjia.view.activity.supermarket.ShangPinActivity;
import com.lwj.liwanjia.view.activity.supermarket.ShangpinDetailActivity;
import com.superrecycleview.superlibrary.adapter.SuperBaseAdapter;
import com.superrecycleview.superlibrary.recycleview.SuperRecyclerView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 顶部菜单弹出
 */

public class PopUtils {
    private static PopUtils popUtils;
    private int selection;

    public static PopUtils getInstance() {
        if (popUtils == null) {
            synchronized (PopUtils.class) {
                if (popUtils == null) {
                    popUtils = new PopUtils();
                }
            }
        }
        return popUtils;
    }

    /**
     * 导航栏分类
     *
     * @param context
     * @param view
     */
    public void showPopupWindow(final Context context, ImageView view) {
        View view1 = LayoutInflater.from(context).inflate(R.layout.popup_caidan_layout, null);
        final PopupWindow popupWindow = new PopupWindow(view1, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
        //设置弹出窗体不可点击
        popupWindow.setFocusable(false);
        //实例化一个ColorDrawable,点击窗体外部区域时消失
        ColorDrawable cd = new ColorDrawable();
        popupWindow.setBackgroundDrawable(cd);
        popupWindow.setOutsideTouchable(true);
        //弹出位置
        popupWindow.showAsDropDown(view, 0, 0);
        ViewHolder holder = new ViewHolder(view1);
        holder.number.setText(SpfUtils.getSpfUtils(context).getGwcNumber()+"");
        //回到首页
        holder.tabHome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context, MainActivity.class));
                popupWindow.dismiss();
            }
        });
        //回到订单界面
        holder.tabIndent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, MyIndentActivity.class);
                intent.putExtra("type", "0");
                context.startActivity(intent);
                popupWindow.dismiss();
            }
        });
        //跳转到购物车
        holder.tabGouwuche.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(context, MainActivity.class);
                intent1.putExtra("type", "购物车");
                context.startActivity(intent1);
                popupWindow.dismiss();
            }
        });
    }

    static class ViewHolder {
        @BindView(R.id.tab_home)
        LinearLayout tabHome;
        @BindView(R.id.tab_indent)
        LinearLayout tabIndent;
        @BindView(R.id.tab_gouwuche)
        LinearLayout tabGouwuche;
        @BindView(R.id.gouwuche_number)
        TextView number;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
